package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.dlc.shop.bean.model.Category;
import com.dlc.shop.bean.model.CategoryShop;
import com.dlc.shop.bean.vo.CategoryShopVO;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author lhd
 * 分类数据
 *
 */
public class CategoryApi {

    /**
     * 查询一级分类
     * @return
     */
    public static List<Category> listCategoryByGrade() {
        String url = Constant.PLATFORM_URL + "/prod/category/listCategoryByGrade?grade = 0";
        return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class)), Category.class);
    }


    /**
     * 获取店铺签约的可用分类列表(发布商品时使用）
     */
    public static List<Category> listCategory() {
        String url = Constant.SHOP_URL + "/prod/category/listCategory?status = 1";
        return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class)), Category.class);
    }

    public static List<Category> listAvailableSigningCategory() {
        String url = Constant.SHOP_URL + "/prod/category/listAvailableSigningCategory";
        return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class)), Category.class);
    }

    /**
     * 根据分类id查找分类信息
     * @param categoryId
     * @return
     */
    public static Category getCategoryByGrade(Long categoryId){
        String url = Constant.PLATFORM_URL + "/prod/category/info/" + categoryId;
        return HttpUtil.get(url, Category.class);

    }

    /**
     * 修改分类信息
     * @param category
     */
    public  static void update(Category category){
        String url = Constant.PLATFORM_URL + "/prod/category";
        HttpUtil.put(url, category);
    }

    /**
     * 创建分类
     * @param category
     */
    public static Long sava(Category category){
        String url = Constant.PLATFORM_URL + "/prod/category";
        return HttpUtil.post(url, category, Long.class, true);
    }

    /**
     * 店铺增加签约分类
     * @param categoryShop
     */
    public static void addSigningCategory(CategoryShop categoryShop, Long shopId){
        String url = Constant.SHOP_URL + "/shop/signingAuditing/addSigningCategory";
        HttpUtil.post(url, Arrays.asList(categoryShop), Object.class, Objects.equals(shopId, 1L) ? true : false);
    }


    /**
     * 创建平台分类
     */
    public static Long save(Category category){
        String url = Constant.PLATFORM_URL + "/prod/category";
        return HttpUtil.post(url, category, Long.class);
    }

    /**
     * 根据平台分类Id获取平台分类信息
     */
    public static Category info(Long categoryId){
        String url = Constant.PLATFORM_URL + "/prod/category/info/" + categoryId;
        return HttpUtil.get(url, Category.class);
    }


    /**
     * 商家签约平台分类
     */
    public static void addSigningCategory(List<CategoryShop> categoryShopList){
        String url = Constant.SHOP_URL + "/shop/signingAuditing/addSigningCategory";
        HttpUtil.post(url, categoryShopList);
    }

    /**
     * 获取商家签约平台分类列表
     */
    public static List<CategoryShopVO> listSigningCategory(){
        String url = Constant.SHOP_URL + "/prod/category/listSigningCategory";
        return JSON.parseArray(JSON.toJSONString(HttpUtil.get(url, List.class)), CategoryShopVO.class);
    }

    /**
     * 商家删除签约的平台分类
     */
    public static void deleteSingingCategory(Long categoryId){
        String url = Constant.SHOP_URL + "/shop/signingAuditing/deleteSigningCategory?categoryId=" + categoryId;
        HttpUtil.delete(url);
    }

    /**
     * 删除平台分类
     */
    public static void delete(Long categoryId){
        String url = Constant.PLATFORM_URL + "/prod/category/" + categoryId;
        HttpUtil.delete(url);
    }

    /**
     * 创建店铺分类
     */
    public static Long saveShopCategory(Category shopCategory){
        String url = Constant.SHOP_URL + "/prod/category";
        return HttpUtil.post(url, shopCategory, Long.class, true);
    }

    /**
     * 根据店铺分类Id获取店铺分类信息
     */
    public static Category infoShopCategory(Long shopCategoryId){
        String url = Constant.SHOP_URL + "/prod/category/info/" + shopCategoryId;
        return HttpUtil.get(url, Category.class);
    }

    /**
     * 更新店铺分类
     */
    public static void updateShopCategory(Category shopCategory){
        String url = Constant.SHOP_URL + "/prod/category";
        HttpUtil.put(url, shopCategory);
    }

    /**
     * 删除店铺分类
     */
    public static void deleteShopCategory(Long shopCategoryId){
        String url = Constant.SHOP_URL + "/prod/category/" + shopCategoryId;
        HttpUtil.delete(url);
    }

}
